<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .undo-list {
      padding: 10px;
      margin: 30px auto;
      width: 300px;
      border: solid red;
    }


    .done-list {
      padding: 10px;
      margin: 0 auto;
      width: 300px;
      border: solid green;
    }

    .task {
      margin: 10px 0;
      display: flex;
      justify-content: space-between;
    }

    .undo-list .cancel {
      display: none;
    }
  </style>
</head>

<body>
  <div class="undo-list">
    <h2>待办清单</h2>
    <div class="task-list">
      <div class="task">
        <p>吃饭</p>
        <button class="cancel">未完成</button>
        <button class="finish">完成</button>
        <button class="delete">删除</button>
      </div>
      <div class="task">
        <p>睡觉</p>
        <button class="cancel">未完成</button>
        <button class="finish">完成</button>
        <button class="delete">删除</button>
      </div>
      <div class="task">
        <p>代码</p>
        <button class="cancel">未完成</button>
        <button class="finish">完成</button>
        <button class="delete">删除</button>
      </div>
    </div>
  </div>

  <div class="done-list">
    <h2>已完成</h2>
    <div class="task-list"></div>
  </div>

  <script>
    var cancelBtnList = document.querySelectorAll('.cancel');
    var finishBtnList = document.querySelectorAll('.finish');
    var deleteBtnList = document.querySelectorAll('.delete');
    var undoList = document.querySelector('.undo-list');
    var doneList = document.querySelector('.done-list');

    finishBtnList.forEach(function (button) {
      button.onclick = function () {
        doneList.appendChild(button.parentNode);
        button.style.display = 'none';
      };
    });

    cancelBtnList.forEach(function (button) {
      button.onclick = function () {
        undoList.appendChild(button.parentNode);
        button.nextElementSibling.style.display = '';
      }
    })

    deleteBtnList.forEach(function (button) {
      button.onclick = function () {
        button.parentNode.remove();
      };
    });

  </script>
</body>

</html>